import request from './request.js'
import { Decrypt } from '@/utils/aes.js'

// 账号密码登录接口
export function loginByJson(params){
    return request({
        url:'/api/u/loginByJson',
        method:'POST',
        data:params
    })
}

// 创建token
export function createToken(){
    return request({
        url:'/api/token/createToken',
        method:'POST'
    })
}

//获取个人信息
export function getInfo({token}){
    return request({
        url:'/api/member/getInfo?token=' + token,
        method:'GET',
        headers:{
            // 本地保存的accessToken
            'Authorization': Decrypt(localStorage.getItem('token'))
        }
    })
}

//手机验证码登录
export function loginByMobile(params){
    return request({
        url:'/api/u/loginByMobile',
        method:'POST',
        data:params
    })
}

//手机验证码注册
export function register(params){
    return request({
        url:'/api/member/register',
        method:'POST',
        data:params
    })
}

// 修改手机号
export function modifyMobile({token,...params}){
    return request({
        url:'/api/member/modifyMobile',
        method:'POST',
        data:params,
        headers:{
            // 本地保存的accessToken
            'Authorization': Decrypt(localStorage.getItem('token')),
            'token':token
        }
    })
}

// 退出登录
export function logout(){
    return request({
        url:'/api/u/logout',
        method:'GET',
    })
}